// TOWN SCRIPT
//    Town 19: Philippi (after winning)

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
// 19, 0 = entry message flag
// 19, 1 = roost flag
// 19, 2 = guard message flag
// 19, 3 = hm message flag
// 5, 4 = trap disarmed flag (original city flag)
// 19, 5 = mayor assistant conversation flag
// 19, 6 = perm to see major flag
// 19, 7 = mayor entry message flag
// 19, 8 = drink flag

begintownscript;

variables;

short choice, x, y, ds;
string msgx;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(5);
	enable_add_chars(TRUE);

	set_name(33, "Mayor Tom");
	set_char_dialogue_pic(33, 536, 0);
	set_name(34, "Nadya");
	set_char_dialogue_pic(34, 532, 0);
	set_name(35, "Origen");
	set_char_dialogue_pic(35, 535, 0);
	set_name(36, "Adelard");
	set_char_dialogue_pic(36, 1946, 0);
	set_name(37, "Thalia");
	set_char_dialogue_pic(37, 538, 0);
	set_name(38, "Nancy");
	set_char_dialogue_pic(38, 539, 0);
	set_name(39, "Jodie");
	set_char_dialogue_pic(39, 534, 0);
	set_name(40, "Gelidia");
	set_char_dialogue_pic(40, 530, 0);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	if (get_flag(19, 0) == FALSE) {
		set_flag(19, 0, TRUE);
		reset_dialog();
		add_dialog_str(0, "The port city of Philippi, the largest city in The Wilderness, is well defended.", 0);
		add_dialog_str(1, "With The Wilderness set free of the anarchy that once ruled it, ships are now scheduled to dock.", 0);
		add_dialog_str(2, "In addition, citizens that left are in the process of returning, bringing more life and vitality to the city.", 0);
		add_dialog_str(3, "Hopefulness is once again evident in the air, everywhere you look.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(TRUE);
	}
	if (get_ran(1, 0, 100) < 10) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(6, "Woof Woof");
		}
		else {
			text_bubble_on_char(6, "Grrrrr");
		}
	}
	if (get_ran(1, 0, 100) < 10) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(7, "Purrrrr");
		}
		else {
			text_bubble_on_char(7, "Meow");
		}
	}
break;

beginstate 10;
	// sewers are locked up now...
break;

beginstate 11;
break;

beginstate 12;
break;

beginstate 13;
break;

beginstate 14;
	print_str_color("The sewer cover is locked firmly in place.", 4);
break;

beginstate 15;
	x = 34;
	y = 22;
	ds = 11;
	set_state_continue(20);
break;

beginstate 16;
	x = 34;
	y = 19;
	ds = 10;
	set_state_continue(20);
break;

beginstate 17;
	x = 31;
	y = 19;
	ds = 15;
	set_state_continue(20);
break;

beginstate 18;
	x = 28;
	y = 19;
	ds = 16;
	set_state_continue(20);
break;

beginstate 19;
	x = 30;
	y = 20;
	ds = 17;
	set_state_continue(20);
break;

beginstate 20;
	if (get_flag(19, 1) > 0) {
		set_flag(19, 1, FALSE);
		teleport_party(x, y, 1);
		give_ter_script_message(ds, 1);
		revive_party();
		set_ticks_forward(1500);
		force_instant_terrain_redraw();
		message_dialog("The room was at least private and clean.", "You awake relaxed and rested.");
	}
break;

beginstate 21;
	if (get_flag(19, 2) == FALSE) {
		set_flag(19, 2, TRUE);
		message_dialog("A small sign attached to the doors reads: 'Philippi Guard'", "");
	}
break;

beginstate 22;
	if (get_flag(19, 3) == FALSE) {
		set_flag(19, 3, TRUE);
		message_dialog("The harbor master's office is empty.",
			 "Though it does look like someone's cleaned up and somebody will soon be manning the desks again.");
	}
break;

beginstate 23;
	set_flag(19, 6, FALSE);
	set_flag(19, 7, FALSE);
break;

beginstate 24;
	clear_buffer();
	if ((char_ok(36)) && (get_flag(19, 6) == FALSE)) {
		block_entry(TRUE);
		if (get_flag(19, 5) == TRUE) {
			append_char_name(36);
		}
		else {
			append_string("The mayor's assistant");
		}
		append_string(" stops you before you reach the door.");
		get_buffer_text(msgx);
		message_dialog(msgx, "'You must sign the visitor log before you can see the mayor.' he growls.");
	}
	else {
		block_entry(FALSE);
		if (get_flag(19, 7) == FALSE) {
			set_flag(19, 7, TRUE);
			append_char_name(36);
			append_string(" waves you through the door to see the mayor.");
			get_buffer_text(msgx);
			if (char_ok(36)) {
				message_dialog(msgx, "");
			}
		}
	}
break;
